﻿using Net.Client;
using Net.Event;
using Net.Server;
using Net.Share;
using System;
using System.Threading;
using System.Threading.Tasks;
using UdpClient = Net.Client.UdpClient;

namespace ConsoleApp4
{
    class ser : UdpServer<NetPlayer, NetScene<NetPlayer>>
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "udp";
            int num = 128;
            if (args.Length == 1)
                num = int.Parse(args[0]);
            NDebug.BindLogAll(Console.WriteLine);//打印服务器,客户端日志
            ser server = new ser();
            server.AddAdapter(new Net.Adapter.SerializeAdapter());
            server.AddAdapter(new Net.Adapter.CallSiteRpcAdapter<NetPlayer>());
            server.Start(6661);
            server.SetHeartTime(5, 1000);

            Thread.Sleep(200);

            ClientBase client = new UdpClient();
            client.OnPingCallback += (time) => { Console.Title = "udp-client " + time; };
            client.SetHeartTime(5, 1000);
            client.AddAdapter(new Net.Adapter.SerializeAdapter());
            client.AddAdapter(new Net.Adapter.CallSiteRpcAdapter());
            client.AddRpcHandle(new Program());

            client.Connect("127.0.0.1", 6661).Wait();
            client.Send(new byte[1]);
            Thread.Sleep(1000);
            Task.Run(() =>
            {
                int i = 1;
                while (true)
                {
                    Thread.Sleep(1);
                    client.SendRT(NetCmd.LocalRT, "Test", i);
                    i++;
                }
            });
            Console.ReadLine();
        }

        [Rpc]
        void Test(int i)
        {
            Console.WriteLine(i);
        }
    }
}